# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# AUR Maintainer: Alex Sarum <rum.274.4 at gmail dot com>

pkgname=imhex
pkgver=nightly.r2.g0488c99
pkgrel=1
epoch=6
pkgdesc='A Hex Editor for Reverse Engineers, Programmers and people that value their eye sight when working at 3 AM.'
arch=('x86_64')
groups=('blackarch' 'blackarch-misc')
url='https://github.com/WerWolv/ImHex'
license=('GPL2')
depends=('glfw' 'glm' 'capstone' 'llvm-libs' 'llvm' 'nlohmann-json' 'python'
         'file' 'gtk3' 'mbedtls' 'libssh2' 'curl' 'dbus' 'freetype2' 'yara'
         'hicolor-icon-theme' 'xdg-desktop-portal-gtk' 'fmt')
makedepends=('git' 'cmake' 'freetype2' 'llvm' 'gcc' 'lld'  'librsvg')
source=("$pkgname::git+https://github.com/WerWolv/ImHex.git")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $pkgname

  git submodule update --init --recursive
  cmake -B build -Wno-dev \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_SKIP_RPATH=ON \
    -DUSE_SYSTEM_LLVM=ON \
    -DUSE_SYSTEM_YARA=ON \
    -DUSE_SYSTEM_FMT=ON \
    -DUSE_SYSTEM_CURL=ON \
    -DUSE_SYSTEM_NLOHMANN_JSON=ON \
    -DUSE_SYSTEM_CAPSTONE=OFF
  make -C build
}

package() {
  cd $pkgname

  install -Dm 755 "build/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 755 build/lib/libimhex/libimhex.so "$pkgdir/usr/lib/libimhex.so"
  install -Dm 644 build/plugins/builtin.hexplug \
    "$pkgdir/usr/share/$pkgname/builtin.hexplug"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
}

